<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AdminLoginModel
 *
 * @author Animus Inc.
 */

define('DOMROOT', dirname(dirname(__FILE__)));

// imports

require_once DOMROOT.'/AnimusORM/classes/AnimusORM.php';
require_once DOMROOT.'/classes/abstract/Model.php';

class AdminLoginModel extends Model{
    
    private $_attributes;
    private $_view_attributes;
    private $_db;
    private $_user_login_details;
    
    public function __construct(){
        $this->_attributes = array();
        $this->_db = AnimusORM::startORM();
        $this->_user_login_details = $this->_db->getRelationalEntity("_user_login_details");
        return true;
    }
    
    public function setDBAttribute($_key,$_value){
        $this->_attributes[$_key] = $_value;
        return true;
    }
    
    public function setDBAttributes( $attributes){
        $this->_attributes = $attributes;
        return true;
    }
    
    public function bindParams(){
        $this ->_user_login_details -> reset();
        foreach($this->_attributes as $key => $value){
            
            $this->_user_login_details->bindValue($key, $value);
        }
        return true;
    }
    
    
    public function fetch($target, $discriminator){
        
        /*
         * $target => The output field
         * $name => Name of discriminator field
         * $value => Value of discriminator field
         */
        $this ->bindParams();
        $this -> _user_login_details -> getColumnByName($target) -> toFetch();
        $this -> _db ->select($this->_user_login_details, $target, $discriminator);
        return $this -> _user_login_details -> getColumnByName($target) -> getFetchedField();
        
    }
    
    public function fetchArray($target_array, $discriminator){
        
        $fetched_array = array();
        $this ->bindParams();
        foreach($target_array as $target){    
            $this -> _user_login_details -> getColumnByName($target) -> toFetch();
        }
        
        $this -> _db ->select($this->_user_login_details, $target_array, $discriminator);
        
        foreach($target_array as $target){
            $fetched_array[$target] = $this -> _user_login_details -> getColumnByName($target) -> getFetchedField();
        }
        return $fetched_array;
    }
    public function setViewData($attributes) {
        $this->_view_attributes = $attributes;
    }
    public function getViewData(){
        return $this ->_view_attributes;
    }
}
?>